home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / mod2tutb.zip / ADRSTUFF.MOD next >
Text File  |  1989-01-18  |  1KB  |  57 lines

  1.                                         (* Chapter 14 - Program 3 *)
  2. MODULE AdrStuff;
  3.  
  4. FROM InOut   IMPORT WriteInt, WriteLn;
  5. FROM SYSTEM  IMPORT ADR, SIZE, TSIZE, ADDRESS;
  6.  
  7. TYPE IntArray = ARRAY[1..8] OF INTEGER;
  8.      BigArray  = ARRAY[1..5] OF IntArray;
  9.  
  10. VAR  Stuff     : BigArray;
  11.      NeatPoint : ADDRESS;
  12.      IncreAmt  : CARDINAL;
  13.      Index     : INTEGER;
  14.      Count     : INTEGER;
  15.      Amount    : INTEGER;
  16.  
  17. BEGIN
  18.                               (* Load the array with nonsense data *)
  19.    FOR Index := 1 TO 8 DO
  20.       FOR Count := 1 TO 5 DO
  21.          Stuff[Count][Index] := Index + 10 * Count;
  22.       END;
  23.    END;
  24.                          (* Perform some simple pointer operations *)
  25.    NeatPoint := ADR(Stuff[1][1]);
  26.    Index := INTEGER(NeatPoint^);
  27.    WriteInt(Index,6);
  28.    IncreAmt := TSIZE(IntArray);
  29.    NeatPoint := NeatPoint + IncreAmt;
  30.    Index := INTEGER(NeatPoint^);
  31.    WriteInt(Index,6);
  32.    WriteLn;
  33.                       (* Perform some pointer operations in a loop *)
  34.    Count := INTEGER(TSIZE(BigArray)) DIV INTEGER(TSIZE(IntArray));
  35.    FOR Index := 1 TO Count DO
  36.       NeatPoint := ADR(Stuff[1][1]) +
  37.                      CARDINAL((Index-1)*(INTEGER(TSIZE(IntArray))));
  38.       Amount := INTEGER(NeatPoint^);
  39.       WriteInt(Amount,6);
  40.    END;
  41.  
  42.    IncreAmt := SIZE(Stuff);
  43.    Count := INTEGER(SIZE(NeatPoint));
  44.  
  45. END AdrStuff.
  46.  
  47.  
  48.  
  49.  
  50. (* Result of execution
  51.  
  52.     11    21
  53.     11    21    31    41    51
  54.  
  55. *)
  56.  
  57.